package com.bc.mes.device.service.impl;

import com.bc.mes.device.service.DvMachineryService;
import com.bc.mes.mbg.mapper.DvMachineryMapper;
import com.bc.mes.mbg.model.dv.DvMachinery;
import com.bc.mes.mbg.model.dv.DvMachineryExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * --- 天道酬勤 ---
 *
 * @author zhangpingan
 * @date 2024/7/11
 * @desc
 */
@Component
public class DvMachineryServiceImpl implements DvMachineryService {

    @Autowired
    private DvMachineryMapper dvMachineryMapper;

    @Override
    public List<DvMachinery> listMachinery(String machineryCode, String machineryName, Long machineryTypeId) {

        DvMachineryExample dvMachineryExample = new DvMachineryExample();
        DvMachineryExample.Criteria criteria = dvMachineryExample.createCriteria();
        if (machineryCode != null && machineryCode != "") {
            criteria.andMachineryCodeLike("%" + machineryCode + "%");
        }
        if (machineryName != null && machineryName != "") {
            criteria.andMachineryNameLike("%" + machineryName + "%");
        }
        if (machineryTypeId != null) {
            criteria.andMachineryTypeIdEqualTo(machineryTypeId);
        }

        List<DvMachinery> dvMachineries = dvMachineryMapper.selectByExample(dvMachineryExample);


        return dvMachineries;
    }

    @Override
    public DvMachinery selectById(Long id) {
        return dvMachineryMapper.selectByPrimaryKey(id);
    }

    @Override
    public int update(DvMachinery dvMachinery) {
        int i = dvMachineryMapper.updateByPrimaryKeySelective(dvMachinery);
        return i;
    }
}
